<?php
/**
* 	KVCache class
*	Date: 	2011-5-23
*	Author:	terrywu
*/
class KVCache{

	protected	$cache_name;
	protected	$expire;
	protected	$h_param;
	protected	$cache_obj;
	protected	$cache_type;

	function __construct($cache_name='',$h_param=array()){
		if(!empty($cache_name)){
			$this->cache_name = $cache_name;
		}
		$cacheclass = $this->factory();
		$this->cache_obj = new $cacheclass($this,$h_param);
		$this->h_param = $h_param;
	}

	/** 選擇CACHE類
	* @return	cacheclass name
	*/
	private function factory(){
		global $kvcache;
		
		$cache_type = get_hash_param($kvcache,'cache_type','');
		if(!empty($cache_type)){
			require_cache(LIB_PATH.'/KVCache/'.$cache_type.'.class.php');
			$this->cache_type = $cache_type;
			return $cache_type;
		}else{
			die('cache_type error');
		}
	}

	final function get($key_in){
		return $this->cache_obj->get($key_in);
	}

	final function mget($a_key){
		return $this->cache_obj->mget($a_key);
	}
	
	final function mget_hash($a_key){
		return $this->cache_obj->mget_hash($a_key);
	}
	
	final function set($key_in, $value, $expire=null){
		return $this->cache_obj->set($key_in, $value, $expire);
	}

	final function mset($h_value){
		return $this->cache_obj->mset($h_value);
	}
	
	final function incr($key_in, $value_inc){
		return $this->cache_obj->incr($key_in, $value_inc);	
	}

	final function decr($key_in, $value_decr){
		return $this->cache_obj->decr($key_in, $value_decr);
	}
	
	final function del($key_in){
		return $this->cache_obj->del($key_in);	
	}

	final function mdel($a_key){
		return $this->cache_obj->mdel($a_key);	
	}

	final function get_cache_status(){
		return $this->cache_obj->get_cache_status();
	}

	final function get_cache_type(){
		return $this->cache_type;
	}

	final function get_cache_name(){
		if(isset($this->cache_name)){
			return $this->cache_name;
		}else{
			return '';
		}
	}
	
	final function get_cache_expire(){
		if(isset($this->expire)){
			return $this->expire;
		}else{
			return '-1';
		}
	}

	function create_cache_content($key){
		return '';
	}

}
?>
